package com.xiangban.xiangbanmall.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.xiangban.xiangbanmall.dao.WalletRecordMapper;
import com.xiangban.xiangbanmall.model.TUserWalletRecord;
import com.xiangban.xiangbanmall.utils.CommonUtils;
import com.xiangban.xiangbanmall.utils.PageUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

import static com.xiangban.xiangbanmall.utils.CommonUtils.BizEmpty;

/**
 * @Author Mr. MaYaYun
 * @Data 2021/11/1 15:47
 */
@Service
public class BillService {

    @Autowired
    private WalletRecordMapper billMapper;
    @Autowired
    private CommonUtils commonUtils;
    @Autowired
    private PageUtil pageUtil;





    public void addUserWalletRecord(TUserWalletRecord tUserWalletRecord) {
        if (BizEmpty(tUserWalletRecord.getUserId())){
            String userIdByToken = commonUtils.getUserIdByToken();
            tUserWalletRecord.setUserId(Integer.parseInt(userIdByToken));
        }
        billMapper.insertUserWalletRecord(tUserWalletRecord);
    }

    public PageInfo<TUserWalletRecord> getUserWalletRecord() {
//        if (BizEmpty(commonUtils.getUserIdByToken())){
//            throw new BizException(ApiResultCode.PARAMETER_DEFICIENCY);
//        }
        PageHelper.startPage(pageUtil.getPage().getPageNum(),pageUtil.getPage().getPageSize());
        int userId = Integer.parseInt(commonUtils.getUserIdByToken());
        List<TUserWalletRecord> tUserWalletRecords = billMapper.selectUserWalletRecordList(userId);
        return new PageInfo<>(tUserWalletRecords);

    }
}
